/**
  ******************************************************************************
  * @file    HCI_KEY_STAPAGE.c
  * @author  Feirui_Joe
  * @version V0.1
  * @date    07/26/2010
  * @brief   ACAD Handling
  ******************************************************************************
  * @copy
  *
  * <h2><center>&copy; COPYRIGHT 2010 Feirui</center></h2>
  */ 



/**
  * @brief  INCLUDE FILES.
  */
#ifndef	HCI_KEY_STAPAGE_GLOBALS
#define	HCI_KEY_STAPAGE_GLOBALS
#include <includes.h>


static const uint8_t * const KFTouchStaDspAdrListTbl[];


/*******************************************************************/
/*******************************************************************/
/* Status Page Button */

uint8_t HCIStatusPageButtonHandling(uint8_t ButtonPressSta,uint8_t *ActInform)
{
	uint8_t HCIAction=DEF_FALSE;
	
	uint8_t TempButton=ButtonPressSta;
	if(TempButton>=KeyVOrder_Up)
		TempButton-=KeyVOrder_Up;
  HCIAction|=KeyflowTouchSourceHandle(NULL,KFTouchStaDspAdrListTbl[TempButton],ButtonPressSta,ActInform);
  
  
  /* Level1 Page Changing */
  if(HCIAction&(HCIActionBit_LVxINCAct1|HCIActionBit_LVxDECAct1))
  {
    DisplayRemoteLastSta=DEF_DspInvaildSta;
    DisplayATSLoadFlashSta=DEF_DspInvaildSta;
    DisplayWarningSta=DEF_DspInvaildSta;
  }
  
  
  /* Dsp Mode Vaild Range  */
  if(HCIAction&HCIActionBit_LVxINCAct1)
  {
  	/* Level 1 */
  	if(HCIDisplayMode[HCIDspModeOrdLevel1]>HCIDspModeLV1_StatusMaxPage)
  		HCIDisplayMode[HCIDspModeOrdLevel1]=HCIDspModeLV1_Summary;
    
    //Pump controller Page
    if(GetDataBaseDataContent(AdrApp_APPOption2)&PcfgAPPOptBit_PumpControllerOpt)
    	if(HCIDisplayMode[HCIDspModeOrdLevel1]>=HCIDspModeLV1_LoadSta && HCIDisplayMode[HCIDspModeOrdLevel1]<=HCIDspModeLV1_MainSta)
  		  HCIDisplayMode[HCIDspModeOrdLevel1]=HCIDspModeLV1_WarnRecord;
    
    //Disable Load State Page
    if(GetDataBaseDataContent(AdrApp_APPOptions)&PcfgAPPOptBit_LoadPageDisableOpt)
    	if(HCIDisplayMode[HCIDspModeOrdLevel1]==HCIDspModeLV1_LoadSta)
  		  HCIDisplayMode[HCIDspModeOrdLevel1]=HCIDspModeLV1_GenSta;
  }
  else if(HCIAction&HCIActionBit_LVxDECAct1)
  {
  	/* Level 1 */
  	if(HCIDisplayMode[HCIDspModeOrdLevel1]>HCIDspModeLV1_StatusMaxPage)
  		HCIDisplayMode[HCIDspModeOrdLevel1]=HCIDspModeLV1_StatusMaxPage;
    
    //Pump controller Page
    if(GetDataBaseDataContent(AdrApp_APPOption2)&PcfgAPPOptBit_PumpControllerOpt)
    	if(HCIDisplayMode[HCIDspModeOrdLevel1]>=HCIDspModeLV1_LoadSta && HCIDisplayMode[HCIDspModeOrdLevel1]<=HCIDspModeLV1_MainSta)
  		  HCIDisplayMode[HCIDspModeOrdLevel1]=HCIDspModeLV1_EngineSta;
    
    //Disable Load State Page
    if(GetDataBaseDataContent(AdrApp_APPOptions)&PcfgAPPOptBit_LoadPageDisableOpt)
    	if(HCIDisplayMode[HCIDspModeOrdLevel1]==HCIDspModeLV1_LoadSta)
  		  HCIDisplayMode[HCIDspModeOrdLevel1]=HCIDspModeLV1_EngineSta;
  }
  else if(HCIAction&HCIActionBit_LVxINCAct2)
  {
    /* Level 2 */
    if(HCIDisplayMode[HCIDspModeOrdLevel1]==HCIDspModeLV1_WarnRecord)
    {
    	uint16_t RecordNum=GetDataBaseDataContent(AdrRecord_EventRecordTOTNum);
      if(HCIDisplayMode[HCIDspModeOrdLevel2]>=RecordNum)
      	HCIDisplayMode[HCIDspModeOrdLevel2]=0;
    }
	else if(HCIDisplayMode[HCIDspModeOrdLevel1]==HCIDspModeLV1_GenRecord)
    {
    	uint16_t RecordNum=GetDataBaseDataContent(AdrRecord_GenRecordNum);
      if(HCIDisplayMode[HCIDspModeOrdLevel2]>=RecordNum)
      	HCIDisplayMode[HCIDspModeOrdLevel2]=0;
    }
  }
  else if(HCIAction&HCIActionBit_LVxDECAct2)
  {
    /* Level 2 */
    if(HCIDisplayMode[HCIDspModeOrdLevel1]==HCIDspModeLV1_WarnRecord)
    {
    	uint16_t RecordNum=GetDataBaseDataContent(AdrRecord_EventRecordTOTNum);
      if(HCIDisplayMode[HCIDspModeOrdLevel2]>=RecordNum)
      	HCIDisplayMode[HCIDspModeOrdLevel2]=((RecordNum)?(RecordNum-1):0);
    }
	else if(HCIDisplayMode[HCIDspModeOrdLevel1]==HCIDspModeLV1_GenRecord)
    {
    	uint16_t RecordNum=GetDataBaseDataContent(AdrRecord_GenRecordNum);
      if(HCIDisplayMode[HCIDspModeOrdLevel2]>=RecordNum)
      	HCIDisplayMode[HCIDspModeOrdLevel2]=((RecordNum)?(RecordNum-1):0);
    }
  }
  
  return(HCIAction);
}


/****************************************/
/****************************************/

/* Button Touch Source List */
static const uint8_t KFTouchStaButtonUpRulesTbl[]={
  1,
  KFConditionOrd_CheckStaPageHasLV2,KFActionOrd_DnLV2,
};

static const uint8_t KFTouchStaButtonDownRulesTbl[]={
  1,
  KFConditionOrd_CheckStaPageHasLV2,KFActionOrd_UpLV2,
};

static const uint8_t KFTouchStaButtonLeftRulesTbl[]={
  1,
  KFConditionOrd_NULL,KFActionOrd_DnLV1,
};

static const uint8_t KFTouchStaButtonRightRulesTbl[]={
  1,
  KFConditionOrd_NULL,KFActionOrd_UpLV1,
};

static const uint8_t KFTouchStaButtonHoldEnterRulesTbl[]={
  2,
  KFConditionOrd_CheckPSWVaildPeriod,KFActionOrd_EnterAdvCfgLV3,
  KFConditionOrd_NULL               ,KFActionOrd_EnterAdvCfgLV2,
};

static const uint8_t KFTouchStaButtonESCRulesTbl[]={
  1,
  KFConditionOrd_NULL,KFActionOrd_BackMainPage,
};

static const uint8_t KFTouchStaButtonEnterUpRulesTbl[]={
  1,
  KFConditionOrd_NULL,KFActionOrd_LCDContrastInc,
};

static const uint8_t KFTouchStaButtonEnterDnRulesTbl[]={
  1,
  KFConditionOrd_NULL,KFActionOrd_LCDContrastDec,
};

static const uint8_t * const KFTouchStaDspAdrListTbl[]={
	KFTouchStaButtonUpRulesTbl       ,   /* Up          */
	NULL                             ,   /* Enter       */
	KFTouchStaButtonDownRulesTbl     ,   /* Down        */
	KFTouchStaButtonLeftRulesTbl     ,   /* Left        */
	KFTouchStaButtonRightRulesTbl    ,   /* Right       */
	KFTouchStaButtonESCRulesTbl      ,   /* ESC         */
	KFTouchStaButtonEnterUpRulesTbl  ,   /* Enter_Up    */
	KFTouchStaButtonEnterDnRulesTbl  ,   /* Enter_Down  */
	NULL                             ,   /* Enter_Left  */
	NULL                             ,   /* Enter_Right */
	NULL                             ,   /* Enter_Stop  */
	KFTouchStaButtonHoldEnterRulesTbl,   /* Hold_Enter  */
	NULL                             ,   /* Hold_Up     */
	NULL                             ,   /* Hold_Down   */
	NULL                             ,   /* Hold_Left   */
	NULL                             ,   /* Hold_Right  */
	KFTouchStaButtonESCRulesTbl      ,   /* Hold_ESC    */
	NULL                             ,   /* Hold_Stop   */
};


/*$PAGE*/#endif	/*	HCI_KEY_STAPAGE_GLOBALS	*/
